<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
	<meta name="author" content="">
	<title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
	<% include("../inc/list_css.html"){}%>
</head>
<body>
<div class="ibox ">
	<div class="ibox-title">
		<div class="pull-left mbx navbar_title">
			<span>品牌门店 </span>
			<span class="line">/</span>
			门店管理
		</div>
	</div>

	<div class="ibox-content">
		<div class="wrapper wrapper-content">
			<div class="row">
				<div class="col-md-12">


					<div class="btn-group margin-vertical-4_20">
						<button class="hive-btn-md-large hive-btn-primary" id="add">
							<i class="icon-add" aria-hidden="true"></i>&nbsp;添加门店
						</button>
						<button type="button" class="hive-btn-md-large hive-btn-primary" onclick="exportStore()">导出</button>
						<button type="button" class="hive-btn-md-large hive-btn-primary" onclick="importStore()">导入</button>
						<button type="button" class="hive-btn-md-large hive-btn-primary" onclick="importStoreDemo()">下载导入示例</button>
					</div>
					<div id="eventsToolbar" class="form-inline hive_input">
						地区
						<select name="province" class="form-control" id="location_p"></select>
						<select name="city" class="form-control" id="location_c" ></select>
						<select name="district" class="form-control" id="location_a"></select>
						<script src="/res/plugins/jiuyue/region_select_check.js"></script>
						<script type="text/javascript">
                            new PCAS('province', 'city', 'district', '', '', '');
						</script>
						&nbsp; &nbsp; 门店名称 &nbsp;
						<input class="form-control " id="name" placeholder="请输入门店名称">
						<button class="hive-btn margin-left-5" onclick="look()">&nbsp;搜索&nbsp;</button>


					</div>
					<table data-toggle="table " id="table" data-show-export="true" class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
						<thead class="table-header">
						<tr>
							<th data-field="storeNum">门店编号</th>
							<th data-field="business_name">门店名称</th>
							<th data-field="type" data-formatter="typeFormatter">类型</th>
							<th data-field="pca">省/市/区</th>
							<th data-field="address">地址</th>
							<th data-field="storeCategoryName">门店类别</th>
							<!--<th data-field="status" data-formatter="verifyStatusFormatter">审核状态</th>-->
							<!--<th data-field="status" data-formatter="statusFormatter">状态</th>-->
							<th data-field="head" data-formatter="opFormatter" data-halign="center"  data-align="center" data-width="160">操作</th>
						</tr>
						</thead>
					</table>

				</div>
			</div>
		</div>
	</div>
</div>
<input type ="file" id="importStoreExcel" name="storeFile" style="display: none"/>

<% include("../inc/list_js.html"){}%>
<!-- 自定义js -->
<script src="/res/js/ajaxfileupload.js"></script>
<script>
    //导入示例
    function importStoreDemo() {
        location.href = 'importStoreDemo';
    }
    //数据导入
    function importStore() {
        $('#importStoreExcel').click();
        $('#importStoreExcel').on('change', function () {
            var index = parent.layer.load(0, {
                shade: [0.3,'#fff'] //0.1透明度的白色背景
            });
            $.ajaxFileUpload({
                url: "importStore",
                type: "POST",
                secureuri: false,
                fileElementId: 'importStoreExcel',//file标签的id
                dataType: 'json',//返回数据的类型
                //data: {"id": v},//一同上传的数据
                success: function (data) {
                    parent.layer.close(index);
                    if(data.code==0){
                        layer.msg("导入成功!");
                        //load.stop();
                        setTimeout(function () {
                            location.reload();
                        },1000);
                    }else{
                        layer.msg(data.desc);
                        //load.stop();
                        setTimeout(function () {
                            location.reload();
                        },2000);
                    }

                },
                error:function (data) {
                    parent.layer.close(index);
                    layer.msg("导入失败!");
                    setTimeout(function () {
                        location.reload();
                    },2000);

                }
            });
        })

    }
    //数据导出
    function exportStore() {
        var index = parent.layer.load(0, {
            shade: [0.3,'#fff'] //0.1透明度的白色背景
        });
        var province=$("#location_p").val();
        var city=$("#location_c").val();
        var district=$("#location_a").val();
        var name=$("#name").val().trim();
        location.href = 'exportStore?province='+province+'&city='+city+'&district='+district+'&name='+name;
        parent.layer.close(index);
    }

    function look(){
        var province=$("#location_p").val();
        var city=$("#location_c").val();
        var district=$("#location_a").val();
        var name=$("#name").val();
        $('#table').bootstrapTable("refresh",{query: {province:province,city:city,district:district,name:name}});
    }

    function verifyStatusFormatter(v, row, index) {
        if(v==0){
            return '未推送';
        }else if(v==1){
            return '审核中';
        }else if(v==2){
            return '审核通过';
        }else if(v==3){
            return '审核不通过<a href="reasonDetail?id='+row.id+'" style="margin-left: 10px;">[查看详情]</a>';
        }
    }
    function statusFormatter(v) {
        if(v==0){
            return '正常营业';
        }else if(v==1){
            return '暂停营业';
        }
    }
    function typeFormatter(v) {
        if(v==0){
            return '门店';
        }else if(v==1){
            return '部门';
        }
    }

    function opFormatter(value, row, index){
        var html='';
        if(row.storeStatus==0){
            html += '<a href="javascript:void(0)" class="icon-open-store hive_icon color_normal" onclick="openStore(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="开启门店"></a>';
        }else{
            html += '<a href="javascript:void(0)" class="icon-close-store hive_icon color_normal" onclick="closeStore(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="关闭门店"></a>';
        }
        html += '<a href="javascript:void(0)" class="icon-edit hive_icon color_normal" onclick="edit(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="编辑"></a>';
        html += '<a href="javascript:void(0)" class="icon-delete hive_icon color_danger" onclick="del(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="删除"></a>';
        html += '<a href="javascript:void(0)" class="icon-qrcode hive_icon color_success" onclick="qrcode(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="门店二维码"></a>';
		/*html += '<a href="javascript:void(0)" onclick="pushToWeiXin(\''+row.id+'\');"><span style="margin-left:10px;font-size:15px" class="fa fa-send" data-toggle="tooltip" title="同步到微信公众号"></span></a>';*/
        return html;
    }

    //门店二维码
    function qrcode(v) {
        parent.layer.open({
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            title: ['门店二维码', 'text-align: center;'],
            area: ['320px', '350px'],
            type: 1,
            content: '<div class="bak_co">'
            + '<div class="txbu"><span class="bak_tx"></span><span class="ueser_n"></span></div>'
            + '<div class="qrcode">'
            + '<img class="qrcode_y" src="/shop/brandStore/qrcode?id='+v+'" style="width: 300px">'
            + '</div>'
            + '<div class="qrcode_cr">'
            + '</div>'
            + '</div>',
        });
    }

    function refresh_table() {
        $('#table').bootstrapTable('refresh');
    }


    function openStore(v) {
        $.post('open',{"id":v},function (e) {
            if(e.state == "fail"){
                layer.msg("操作失败");
            }else{
                layer.msg("操作成功!");
                $('#table').bootstrapTable('refresh');
            }
        })
    }

    function closeStore(v) {
        parent.layer.confirm('您确定要关闭门店吗?', {
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            btn: ['是','否'] //按钮
        }, function(){
            $.post('close',{"id":v},function (e) {
                if(e.state == "fail"){
                    parent.layer.msg(e.info);
                }else{
                    parent.layer.msg("操作成功!");
                    $('#table').bootstrapTable('refresh');
                }
            })
        });

    }

    function pushToWeiXin(v) {
        parent.layer.confirm('您确定要同步门店到微信公众号吗?', {
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            btn: ['是','否'] //按钮
        }, function(){
            var index = parent.layer.load(0, {
                shade: [0.3,'#fff'] //0.1透明度的白色背景
            });
            $.post('pushToWeiXin',{"id":v},function (e) {
                if(e.state == "fail"){
                    parent.layer.msg(e.info);
                }else{
                    parent.layer.msg("推送成功!");
                    $('#table').bootstrapTable('refresh');
                }
                parent.layer.close(index)
            })
        });


    }

    function del(v) {
        parent.layer.confirm('您确定要删除吗？若该门店审核通过,微信公众号上的门店也会相应的删除,请谨慎操作!', {
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            btn: ['是','否'] //按钮
        }, function(){
            $.post('delete',{"ids":v},function (e) {
                if(e.state == "fail"){
                    parent.layer.msg(e.info);
                }else{
                    parent.layer.msg("删除成功!");
                    $('#table').bootstrapTable('refresh');
                }
            })
        });

    }
    function edit(v) {
        location.href = "edit?id="+v+"&type=0";
    }
    /**
     * 加载页面数据
     * */
    (function () {

        $('#table').bootstrapTable({
            url: "ajaxlist",
            dataType: 'json',
            contentType: 'application/json',
            search: false,
            searchAlign: 'right',
            pagination: true,
            showRefresh: true,
            pageSize: 20,
            showToggle: false,//是否显示card/table切换按钮
            showColumns: true,//是否显示内容列下拉框
            pageList: [20, 50, 100],
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            paginationHAlign: 'right', //right, left
            paginationVAlign: 'bottom',
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },
            responseHandler: function (res) {
                $("#dsh").html(res.length);
                return res;
            },
            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            },
        });

        $('#add').on('click', function (e) {
            location.href = 'add';
        });

        $(".wrapper").tooltip({selector: "[data-toggle=tooltip]", container: "body"});

    })();
</script>
</body>
</html>